package com.linkhub.oms.data.sync.api.track.domain.response;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author Redball
 * @version 1.0.0
 * @Description TrackBaseResponse
 * @createTime 2024/10/27 上午12:27
 */
@Data
@NoArgsConstructor
public class TrackBaseResponse<T> implements Serializable {

    @JSONField(name = "code")
    private String code;

    @JSONField(name = "data")
    private ResponseData<T> data;

    @JSONField(serialize = false, deserialize = false)
    public Boolean success(){
        return "0".equals(code)&&data!=null && CollUtil.isEmpty(data.errors);
    }

    @Data
    @NoArgsConstructor
    public static class ResponseData<T> {
        @JSONField(name = "accepted")
        private List<T> accepted;

        @JSONField(name = "rejected")
        private List<RejectedData> rejected;

        @JSONField(name = "errors")
        private List<ErrorData> errors;
    }

    @Data
    @NoArgsConstructor
    public static class ErrorData{
        @JSONField(name = "code")
        private String code;

        @JSONField(name = "message")
        private String message;
    }

    @Data
    @NoArgsConstructor
    public static class RejectedData{
        @JSONField(name = "number")
        private String number;

        @JSONField(name = "error")
        private ErrorData error;
    }
}
